package com.details;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class test{
    public static void main(String[] args){
        //java获取背景图片
        ArrayList<String> bacList = new ArrayList<>();
        File bacFile = new File("D:/图片素材/details/moban");
        File[] bacFiles = bacFile.listFiles();
        for (int i = 0; i < bacFiles.length; i++) {
            File file1 = bacFiles[i];
            String fileName = file1.getName();
            String prefix = fileName.substring(fileName.lastIndexOf(".") + 1)
                    .toLowerCase();
            if ("jpg".equals(prefix) || "png".equals(prefix)
                    || "bmp".equals(prefix) || "gif".equals(prefix)) {
                bacList.add(fileName);
            }
        }
        System.out.println(bacList);
        for (String bac:bacList) {
            System.out.println("bac:"+bac);
            String[] splitStrings = bac.split("_");
            String fileNameStr = splitStrings[0];
            int x1 = Integer.parseInt(splitStrings[1]);
            int y1 = Integer.parseInt(splitStrings[2]);
            int x2 = Integer.parseInt(splitStrings[3]);
            int y2 = Integer.parseInt(splitStrings[4]);

            //创建文件夹
            File file11 = new File("D:\\图片素材\\details\\result\\"+fileNameStr);
            if(!file11.exists()){
                file11.mkdir();
            }
            ArrayList<Logo> logoList = new ArrayList<Logo>();
            Logo logo1 = new Logo();
            logo1.setPath("D:\\图片素材\\details\\ui\\1.jpg");
            logo1.setX1(0);
            logo1.setY1(0);
            logo1.setX2(100);
            logo1.setY2(100);
            logoList.add(logo1);

            Logo logo2 = new Logo();
            logo2.setPath("D:\\图片素材\\details\\ui\\1.jpg");
            logo2.setX1(200);
            logo2.setY1(0);
            logo2.setX2(300);
            logo2.setY2(100);
            logoList.add(logo2);

            //设置其他图片水印
            try {
                ImageUtils.margeImage(x1,y1,x2,y2,"D:\\图片素材\\details\\moban\\"+bac,"D:\\图片素材\\details\\ui\\1.jpg",logoList,"D:\\图片素材\\details\\result\\"+fileNameStr+"\\"+fileNameStr+".jpg");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
